﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Trabajo1.LogicaNegocio;

namespace Trabajo1.Presentacion
{
    public partial class Window2 : Window1
    {
        public Window2()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(textbox1.Text))
            {
                var user = ManejadorUsuarios.GetUserByDorsal(int.Parse(textbox1.Text));
                if (user != null)
                {
                    textbox2.Text = user.Nombre;
                    textbox3.Text = user.Apodo;
                }
                else
                {
                    textbox2.Text = "";
                    textbox3.Text = "";
                }
            }
            else
            {
                textbox2.Text = "";
                textbox3.Text = "";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool result = ManejadorUsuarios.SaveUser(int.Parse(textbox1.Text), textbox2.Text, textbox3.Text);

            if (result)
                MessageBox.Show("wiii! :)");
            else
                MessageBox.Show("Morimos :(");
        }
    }
}